//账号/企业切换
$('body>ol>li').click(function () {
    var index = $(this).index();
    $(this).addClass('selected').siblings().removeClass('selected');
    $('body>ul>li').eq(index).addClass('selected').siblings().removeClass('selected');
});
//展开或收起
$('.accinfo>b').click(function () {
    $(this).siblings('div').slideToggle();
    if ($(this).text() == "展开") {
        $(this).text("收起");
    } else {
        $(this).text("展开");
    }
});
//验证文本输入框
var info = new Validated();
info.rules = {
    "linkname": {
        "data": /^[\u4e00-\u9fa5]+$/,
        "complete": "",
        "error": "请输入正确的中文姓名！",
        "normal": "",
        "required": true
    },
    "pwd": {
        "data": /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,
        "complete": "",
        "error": "密码为6-20位数字字母组合！",
        "normal": "",
        "required": true
    },
    "pwd2": {
        "data": /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,
        "complete": "",
        "error": "密码为6-20位数字字母组合！",
        "normal": "",
        "required": true
    },
    "telphone": {
        "data": /^1[3578]\d{9}$/,
        "complete": "",
        "error": "请输入正确的手机号码！",
        "normal": "",
        "required": true
    },
    "yzm": {
        "data": /^\d{6}$/,
        "complete": "",
        "error": "验证码规则错误！",
        "normal": "",
        "required": true
    },
    "yzm2": {
        "data": /^\d{6}$/,
        "complete": "",
        "error": "验证码规则错误！",
        "normal": "",
        "required": true
    },
    "email": {
        "data": /^\w+@\w+\.\w+$/,
        "complete": "",
        "error": "请输入正确的邮箱号码！",
        "normal": "",
        "required": true
    },
    "pwd3": {
        "data": /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,
        "complete": "",
        "error": "密码为6-20位数字字母组合！",
        "normal": "",
        "required": true
    },
    "newPwd": {
        "data": /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,
        "complete": "",
        "error": "密码为6-20位数字字母组合！",
        "normal": "",
        "required": true
    },
    "ackPwd": {
        "data": /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,
        "complete": "",
        "error": "密码为6-20位数字字母组合！",
        "normal": "",
        "required": true
    },
    "account": {
        "data": /^\w{6,30}$/,
        "complete": "",
        "error": "账号为6-30位数字字母下划线组成！",
        "normal": "",
        "required": true
    },
    "pwd4": {
        "data": /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/,
        "complete": "",
        "error": "密码为6-20位数字字母组合！",
        "normal": "",
        "required": true
    },
    "name": {
        "data": /^[\u4e00-\u9fa5]+$/,
        "complete": "",
        "error": "请输入正确的中文姓名！",
        "normal": "",
        "required": true
    },
    "phone": {
        "data": /^1[3578]\d{9}$/,
        "complete": "",
        "error": "请输入正确的手机号码！",
        "normal": "",
        "required": true
    },
    "position": {
        "data": /^.+$/,
        "complete": "",
        "error": "请输入工作岗位！",
        "normal": "",
        "required": true
    },
    "els": {
        "data": /^.+$/,
        "complete": "",
        "error": "请输入正确的els账号！",
        "normal": "",
        "required": true
    },
    "companyName": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "category": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "product": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "size": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "turnover": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "address": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "companyAddr": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "person": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "jobTitle": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "jobTitle": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "mail": {
        "data": /^\w+@\w+\.\w+$/,
        "complete": "",
        "error": "请输入正确的邮箱号码！",
        "normal": "",
        "required": true
    },
    "tel": {
        "data": /^1[3578]\d{9}$/,
        "complete": "",
        "error": "请输入正确的手机号码！",
        "normal": "",
        "required": true
    },
    "Telephone": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "weixin": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "schema": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "credit": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "juristicPerson": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "atm": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "cardNumber": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
//    "found": {
//        "data": /^.+$/,
//        "complete": "",
//        "error": "",
//        "normal": "",
//        "required": true
//    },
    "capital": {
        "data": /^[\d.]+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "domain": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    },
    "licence": {
        "data": /^.+$/,
        "complete": "",
        "error": "",
        "normal": "",
        "required": true
    }
}
info.blur();

//点击申请为供应商
$('#apply').click(function () {
    $(this).css({"background": "#efeded", "color": "#7a7777"}).prev().show().siblings('span').show();
});

//短信发倒计时
var telCheck = true, t = 60;
$('.accinfo .button').eq(0).click(function () {
    var telphone = $('#telphone').val();
    if (!telphone.match(/^1[3578]\d{9}$/)) {
        return false;
    }
    var button = $(this);
    if (telCheck) {
        var s = setInterval(function () {
            t--;
            if (t < 1) {
                clearInterval(s);
                button.text("重新发送");
                t = 60;
                telCheck = true;
                return false;
            }
            button.text(t + "秒后重新发送");
        }, 1000);
    }
    telCheck = false;
});

var emailCheck = true, n = 60;
$('.accinfo .button').eq(1).click(function () {
    var email = $('#email').val();
    if (!email.match(/^\w+@\w+\.\w+$/)) {
        return false;
    }
    var button = $(this);
    if (emailCheck) {
        var s = setInterval(function () {
            n--;
            if (n < 1) {
                clearInterval(s);
                button.text("重新发送");
                n = 60;
                emailCheck = true;
                return false;
            }
            button.text(n + "秒后重新发送");
        }, 1000);
    }
    emailCheck = false;
});

//初始化省级数据
$.each(AreaListData, function (k, v) {
    if (v[1] == 0) {
        $('#province').append('<option value="' + k + '">' + v[0] + '</option>');
    }
});
//初始化市级数据
$.each(AreaListData, function (k, v) {
    if (v[1] == 1) {
        $('#city').append('<option value="' + k + '">' + v[0] + '</option>');
    }
});
//改变/添加 市级数据
$('#province').change(function () {
    $('#city').empty();
    var provinceId = $(this).val();
    $.each(AreaListData, function (k, v) {
        if (v[1] == provinceId) {
            $('#city').append('<option value="' + k + '">' + v[0] + '</option>');
        }
    })
});
//改变/添加 县区级数据
$('#city').change(function () {
    $('#county').empty();
    var cityId = $(this).val();
    $.each(AreaListData, function (k, v) {
        if (v[1] == cityId) {
            $('#county').append('<option value="' + k + '">' + v[0] + '</option>');
        }
    });
});

//日历
$(function () {
    $.datepicker.regional['zh-CN'] = {
        changeYear: true,
        monthNamesShort: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六']
    };
    $.datepicker.setDefaults($.datepicker.regional['zh-CN']);
    $("#defult").datetimepicker();
    $("#found").prop("readonly", true).datepicker({
        changeMonth: true,
        dateFormat: "yy-mm-dd",
    });
    $("#start").prop("readonly", true).datepicker({
        changeMonth: true,
        dateFormat: "yy-mm-dd",
    });
    $("#end").prop("readonly", true).datepicker({
        changeMonth: true,
        dateFormat: "yy-mm-dd",
    });
});